package editor;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

public class DialogApriLivello extends JDialog implements ActionListener {
	private JList listaLivelli;
	private JScrollPane scroll;
	private JButton apri;
	private JButton annulla;
	private EditorFrame ef;
	private JPanel pannelloPrincipale;
	public DialogApriLivello(EditorFrame ef) {
		super();
		this.ef = ef;
		pannelloPrincipale = new JPanel();
		pannelloPrincipale.setLayout(new FlowLayout());
		listaLivelli = new JList(ef.getEditor().getLevels());
		listaLivelli.setPreferredSize(new Dimension (150,200)); 
		scroll = new JScrollPane(listaLivelli);
		scroll.setPreferredSize(new Dimension (180,200));
		apri = new JButton("Apri");
		apri.addActionListener(this);
		annulla = new JButton("Annulla");
		annulla.addActionListener(this);
		pannelloPrincipale.add(scroll);
		pannelloPrincipale.add(apri);
		pannelloPrincipale.add(annulla);
		this.getContentPane().add(pannelloPrincipale);
		this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		this.setTitle("Apri livello");
		this.setSize(200,290);
		this.setLocation(500,300);
		this.setAlwaysOnTop(true);
		this.setVisible(true);
		
	}
	
	public void actionPerformed(ActionEvent e) {
		if (e.getSource()== apri){
			ef.rimuoviTutto();
			ef.impostaPannelli(ef.getEditor().leggiDimensioni((String)listaLivelli.getSelectedValue()),12);
			ef.getEditor().apriLivello((String)listaLivelli.getSelectedValue());
			ef.getChoose().abilitaScelta(true);
			this.dispose();
		}
		else if (e.getSource() == annulla){
			ef.getChoose().abilitaScelta(false);
			this.dispose();
		}
	}
}
